More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
Python IDE Dashboard

Cookie Quizzer – GCSE Revision Quiz!

Struggling to stay motivated while revising for your GCSE Computer Science exams? Meet Cookie Quizzer—the addictive, interactive quiz designed to make revision not just effective, but also fun and addictive!

How It Works
Cookie Quizzer is more than just a quiz. It’s an incremental game that rewards your progress and keeps you coming back for more. Here’s why you’ll love it:

  • Unlimited Questions: Never run out of practice! Cookie Quizzer generates an endless stream of questions, so you can revise as much as you want.
  • Streak System: The longer your streak of correct answers, the bigger your rewards:
    • +10 points for every 5 correct answers in a row.
    • Double points per question when you hit 10 consecutive correct answers.
    • Double your total score when you reach 20 in a row!
  • Save Your Progress: Your score is stored in your browser cookies, so you can pick up right where you left off—anytime, anywhere.

Why It’s Addictive
Inspired by games like Cookie Clicker, Cookie Quizzer turns revision into a challenge. Watch your score soar as you master topics, beat your personal best, and build unstoppable streaks. The more you play, the more you learn—and the more you’ll want to keep going!

Ready to Get Hooked on Revision?
Dive into Cookie Quizzer today and turn your GCSE Computer Science prep into a game. Your future self (and your grades) will thank you!

Ready To Play?
Click on the following cookies to start the quiz:

System Software Quiz (GCSE Level)

Whether you’re preparing for your OCR GCSE Computer Science exam or just curious about how your computer works behind the scenes, understanding system software is essential. From the role of the operating system to the importance of utility programs, these concepts form the backbone of modern computing. Think you’ve got it all figured out? Put your knowledge to the test with our 10-question quiz!

What is System Software?

System software is the backbone of any computer system. Unlike application software, which is designed for end-users to perform specific tasks (like word processing or gaming), system software manages and controls the hardware and provides a platform for applications to run. It includes the operating system (OS), utility programs, and device drivers. Without system software, your computer would be unable to function, as it ensures that hardware components—such as the processor, memory, and storage—work together seamlessly.

The Role of the Operating System


The operating system is the most critical type of system software. It acts as an intermediary between users and the computer hardware. Popular examples include Windows, macOS, and Linux. The OS performs several essential functions: process management, which involves controlling the execution of programs; memory management, ensuring that each application gets the memory it needs; and file management, organising and storing data efficiently.

Additionally, the OS handles user interface management, providing the graphical or command-line interface that allows users to interact with the computer.

Let’s explore some of these most critical functions in more detail.

    User Interface: Your Window to the Computer

    The user interface (UI) is how you interact with your computer. The OS provides two main types of interfaces: Graphical User Interface (GUI) and Command Line Interface (CLI). The GUI, found in systems like Windows and macOS, uses visual elements such as windows, icons, and menus, making it intuitive and user-friendly. On the other hand, the CLI, common in environments like Linux or Windows Command Prompt, relies on text commands, offering more control and efficiency for advanced users. The OS ensures that the UI is responsive, accessible, and tailored to the user’s needs, whether they are a beginner or a professional. Other types of user interfaces such as voice activated interfaces can also be provided by specific OS: e.g. The OS of a smart speaker uses a voice activated user interface (VUI) based on speech recognition.

    Memory Management & Multitasking:

    Memory management is one of the OS’ most complex and vital roles. The OS allocates and deallocates memory (in the RAM) to different applications, ensuring that each program has enough space to run without interfering with others. It loads the relevant programs and data into the RAM and remove these from the RAM when they are no longer needed to optimise the use of essential primary memory.

    Multitasking, meanwhile, allows the OS to run multiple applications simultaneously. The OS rapidly switches between tasks, giving the illusion of parallel execution. This is achieved through process scheduling, where the OS decides which process gets access to the CPU and for how long. Without effective memory management and multitasking, your computer would struggle to handle even basic tasks like browsing the web while listening to music.

    Peripheral Management and Drivers:

    Your computer interacts with a variety of peripheral devices—printers, keyboards, mice, and external storage, to name a few. The OS manages these devices through device drivers, specialised software that acts as a translator between the hardware and the OS. When you plug in a new device, the OS either automatically installs the appropriate driver or prompts you to do so. This ensures that the device functions correctly and can communicate with the rest of the system. Without drivers, peripherals would be unusable, and the OS would be unable to recognize or control them.

    User Management: Security and Personalisation

    User management is all about controlling access and permissions. The OS creates and manages user accounts, each with its own settings, files, and privileges. This allows multiple users to share the same computer while keeping their data separate and secure. The OS also enforces authentication (verifying who you are, usually via passwords or biometrics) and authorization (determining what you’re allowed to do). For example, an administrator account has full control over the system, while a guest account might only be able to access basic features. This layer of security is crucial for protecting sensitive data and preventing unauthorized access.

    File Management: Organising Your Files and Folders

    File management is another cornerstone of the OS’s responsibilities. It involves organizing, storing, and retrieving files efficiently. The OS uses a file system (like NTFS for Windows or APFS for macOS) to keep track of where files are stored on the disk, how they are named, and how they can be accessed. It also handles file permissions, ensuring that users can only access files they have permission to view or modify. Without a robust file management system, finding and managing files would be chaotic, and data could easily become lost or corrupted.

Essential Utility Programs: Keeping Your System Healthy

Utility programs are the unsung heroes of computer maintenance. They work behind the scenes to optimize performance, protect data, and ensure everything runs as it should. Here’s a closer look at some of the most important utilities:

    Encryption Software: Protecting Your Data

    Encryption software is critical for safeguarding sensitive information. It converts data into a coded format that can only be read by someone with the correct decryption key. This is especially important for protecting personal files, financial information, and communications from unauthorized access. Full-disk encryption tools, like BitLocker for Windows or FileVault for macOS, encrypt everything on your hard drive, while other tools allow you to encrypt individual files or folders. In an era where data breaches are common, encryption is a vital layer of security.

    Defragmentation: Speeding Up Your Storage

    Over time, files on a hard drive can become fragmented—scattered across different locations on the disk. This slows down access times, as the computer has to search multiple places to retrieve a single file. Disk defragmentation utilities reorganize these fragmented files, placing them in contiguous blocks. This process improves read and write speeds, making your computer feel faster and more responsive. While defragmentation is less critical for modern solid-state drives (SSDs), it remains important for traditional hard disk drives (HDDs).

    Data Compression: Saving Space and Bandwidth

    Data compression utilities reduce the size of files, making them easier to store and transfer. Compression works by removing redundant data or encoding information more efficiently. Tools like WinZip, 7-Zip, or the built-in compression features in Windows and macOS allow you to create compressed archives (e.g., ZIP or RAR files). This is particularly useful for sending large files over email, backing up data, or freeing up disk space. Compression is also widely used in multimedia files, such as MP3s for audio or JPEGs for images, to balance quality and file size.

Why These Concepts Matter

Understanding these roles and utilities isn’t just academic—it’s practical. Whether you’re troubleshooting a slow computer, setting up a new device, or protecting your data, this knowledge empowers you to make informed decisions. It also lays the foundation for more advanced topics in computer science, such as cybersecurity, software development, and system administration.

Data Representation Quiz (GCSE Level)

Do you have a secure subject knowledge on the key concepts of Data Representation in OCR GCSE Computer Science? Then it’s time to put your understanding to the test! This quiz covers everything from binary and text encoding to image and sound representation, as well as data compression. Whether you are preparing for an exam or just want to reinforce what you have learned, these questions will help you check your knowledge and identify areas to review. Ready to challenge yourself? Let’s get started!

The world of computer science is built on the foundation of data—how it’s stored, processed, and transmitted. In OCR GCSE Computer Science (J277) Component 01, Section 1.3 on Data Representation is a key topic that explains how computers handle everything from numbers and text to images and sound using binary code. Grasping these ideas not only helps with exams but also reveals how digital devices actually work.

Why Binary Matters

At the core of data representation is binary, a base-2 number system that uses only two digits: 0 and 1. Computers rely on binary because electronic circuits can easily switch between two states, like “on” or “off.” Understanding binary involves learning how to convert between binary and denary (base-10) numbers, including the role of place values and how each bit (binary digit) contributes to the overall value. This knowledge is essential for working with both whole numbers and fractions in computing.

Binary isn’t limited to numbers, though. It’s also used to represent text through systems like ASCII and Unicode. ASCII uses 7 or 8 bits to encode characters, while Unicode supports a much broader range of symbols and languages. The difference between these systems highlights how text is stored and displayed in computers, with Unicode offering far greater flexibility for global communication.

Representing Images and Sound

Data representation also covers images and sound. Bitmap images, for example, are composed of pixels, where each pixel’s colour is defined by a binary value. The number of bits per pixel, known as bit depth, determines the range of colours and the image’s quality. Vector graphics, on the other hand, use mathematical equations to create shapes and lines, allowing them to be scaled without losing clarity.

For sound, digital representation involves sampling and quantization. When sound is recorded, it is sampled at regular intervals, and each sample’s amplitude is converted into binary. The sample rate (how frequently samples are taken) and bit depth (the number of bits per sample) directly affect audio quality. Higher sample rates and bit depths produce better sound but result in larger file sizes.

Data Compression and Storage

Given the enormous amounts of data processed by computers, compression plays a vital role in saving space and speeding up transmissions. There are two main types: lossless and lossy compression. Lossless methods, such as Run-Length Encoding (RLE) and Dictionary encoding, reduce file sizes without losing any data, making them ideal for text and certain images. Lossy compression, used in formats like MP3 and JPEG, permanently removes some data to achieve smaller files, which can impact quality but is often necessary for practical use.

File formats also determine how data is stored and accessed. For instance, WAV files store uncompressed audio, while MP3 files use lossy compression to reduce size. Similarly, image formats like PNG and GIF apply different compression techniques, each suited to specific types of visuals.

Errors and Data Integrity (A Level concepts)

Data representation isn’t just about storing information—it’s also about protecting it. Errors can occur during transmission or storage, so techniques like parity bits and checksums help detect issues. More advanced methods, such as error-correcting codes, can even fix errors automatically, ensuring that data remains accurate and reliable. These processes are crucial for everything from downloading files to streaming media.

Bringing It All Together

Section 1.3 of the OCR GCSE Computer Science course explores the fundamental principles that make digital technology possible. Whether converting numbers to binary, encoding text, compressing files, or ensuring data integrity, these concepts are the building blocks of modern computing. By understanding data representation, you gain insight into the systems that power everyday technology, from sending a text message to watching a high-definition video.

Memory and Storage Quiz (GCSE Level)

Memory and storage are the backbone of any computer system, but do you know the difference between RAM and ROM, or how SSDs outperform HDDs? If you are studying for your GCSE Computer Science exams, this quiz is the perfect way to test your knowledge of Memory and Storage. Ready to put your memory to the test? Let’s get started!

Memory and storage are essential components of any computer system, playing a critical role in how data is managed, accessed, and processed.

Primary Memory

Primary memory, often referred to as main memory, is used by a computer to store data and instructions that are actively being used or processed by the CPU (Central Processing Unit). It provides fast access to data, which is essential for the efficient operation of the computer. Except from ROM (Read Only Memory), primary memory is volatile, meaning it loses all stored data when the power is turned off. The three main types of primary memory are ROM (Read-Only Memory), RAM (Random Access Memory) and cache memory.

RAM (Random Access Memory)

RAM, or Random Access Memory, is a type of volatile memory that temporarily stores data and instructions currently in use by the computer’s central processing unit (CPU). Its volatile nature means that all data stored in RAM is lost when the power is turned off. Despite this limitation, RAM is highly valued for its speed, providing much faster access to data compared to secondary storage devices.

ROM (Read-Only Memory)

ROM, or Read-Only Memory, is a type of non-volatile memory that permanently stores data, such as firmware and the bootloader. Unlike RAM, ROM retains its data even when the power is turned off. This makes it ideal for storing essential system instructions that need to be available every time the computer starts up. However, ROM cannot be easily modified, which ensures the integrity of the stored data.

Cache Memory

Cache memory is a small, fast type of memory designed to speed up data access. Positioned between the CPU and RAM, it stores frequently accessed data, reducing the time the CPU needs to retrieve information. By keeping this data readily available, cache memory significantly enhances the overall performance of the computer system.

Secondary Storage

Secondary memory, also known as secondary storage, is used for long-term data storage. Unlike primary memory, secondary memory is non-volatile, meaning it retains data even when the power is turned off. Secondary memory devices, such as hard drives, SSDs, CDs, and USB flash drives, store large amounts of data, including the operating system, software applications, and user files. While secondary memory is slower than primary memory, it provides a much larger storage capacity and is essential for preserving data permanently.

Magnetic Storage

Magnetic storage devices, such as Hard Disk Drives (HDDs), use magnetism to store data. These devices are non-volatile, meaning they retain data even when the power is turned off. While magnetic storage is generally slower compared to solid-state storage, it remains a popular choice due to its cost-effectiveness and large storage capacity.

Optical Storage

Optical storage devices, including CDs, DVDs, and Blu-ray discs, use lasers to read and write data. These devices are non-volatile and offer the advantage of being portable and durable. Optical storage is commonly used for distributing software, music, and movies, as well as for backing up important data.

Solid-State Storage

Solid-state storage devices, such as Solid State Drives (SSDs) and USB flash drives, use flash memory to store data. They are non-volatile and provide faster access to data compared to magnetic storage. Solid-state storage is increasingly popular due to its speed, reliability, and compact size, making it ideal for modern computing needs.

What about Virtual Memory?


Virtual memory is a memory management technique that allows a computer to use secondary storage (like a hard drive or SSD) as an extension of its primary memory (RAM). The main purpose of virtual memory is to enable a system to run larger applications or multiple applications simultaneously, even when the physical RAM is limited. It does this by temporarily transferring data from RAM to a designated space on the secondary storage, known as the swap file or page file, when the RAM becomes full.

A key characteristic of virtual memory is that it provides an illusion of unlimited memory to applications, allowing them to operate as if they have access to more RAM than is physically available. This process is managed by the operating system, which dynamically moves data between RAM and secondary storage as needed. While virtual memory enhances a system’s multitasking capabilities, it can also introduce a performance overhead, as accessing data from secondary storage is significantly slower than accessing it from RAM.

System Architecture Quiz (GCSE Level)

Are you preparing for your GCSE Computer Science exams and want to put your understanding of System Architecture to the test? This quiz is designed to help you reinforce key concepts from the OCR GCSE Computer Science spec. Challenge yourself with 10 multiple-choice questions about System Architecture. Ready to dive in? Start the quiz now!

What Is System Architecture?

System Architecture refers to the structure and organisation of a computer system. It’s about how the hardware components—like the CPU, memory, and storage—work together to process data and execute instructions. Think of it as the blueprint of a computer, explaining how everything connects and functions as a whole.

At this level, you will focus on the Von Neumann architecture, which is the foundation of most modern computers. This architecture consists of four main components: the Central Processing Unit (CPU), memory, input devices, and output devices. These components are connected by buses, which are pathways for data to travel between them.

The Central Processing Unit (CPU)

The CPU is often called the main processing chip of the computer. It’s responsible for executing instructions and performing calculations. To understand the CPU, you need to know about its three main parts: the Arithmetic Logic Unit (ALU), the Control Unit (CU), and the registers.

The ALU performs all the arithmetic and logical operations, such as addition, subtraction, and comparisons. The Control Unit manages the flow of data within the CPU and coordinates the activities of all the other components, ensuring that instructions are fetched, decoded, and executed in the correct sequence. The CPU also operates using a clock, which is a synchronising signal that keeps all parts of the CPU working in time. The speed of the clock, measured in hertz (Hz), determines how many instructions the CPU can process per second—faster clock speeds generally mean faster processing.

Registers are small, fast storage locations within the CPU that hold data temporarily during processing.

The Fetch-Decode-Execute cycle is the process the CPU follows to run instructions. It fetches an instruction from memory, decodes it to understand what needs to be done, executes the instruction, and then repeats the cycle to execute a sequence of instructions (a computer program!).

Memory and Storage

Memory and storage are crucial for holding data and instructions. Primary memory, also known as Random Access Memory (RAM), is volatile, meaning it loses its data when the computer is turned off. RAM is used to store data and instructions that the CPU needs to access quickly.

Secondary storage, such as hard drives and solid-state drives (SSDs), is non-volatile and retains data even when the computer is powered down. You’ll need to understand the differences between these types of memory, including their speed, capacity, and cost.

Another important concept is cache memory, a small, fast type of memory located close to the CPU. It stores frequently used data to speed up processing. The more cache a CPU has, the faster it can perform tasks.

Buses and Data Transfer

Buses are the communication pathways that connect the components of a computer system. There are three main types of buses: the data bus, the address bus, and the control bus.

The data bus carries data between the CPU, memory, and other components. The address bus transmits the memory addresses of where data should be read from or written to. The control bus sends control signals to coordinate the activities of the different components.

Understanding how these buses work together is essential for grasping how data moves around a computer system.

Modern Computers and Multi-Core CPUs

Modern computers often use multi-core CPUs, which contain two or more independent processing units, called cores, within a single CPU chip. Each core can execute its own set of instructions, allowing the CPU to perform multiple tasks simultaneously. This improves overall performance, especially when running complex applications or multitasking.

Multi-core CPUs are essential for tasks like video editing, gaming, and scientific simulations, where large amounts of data need to be processed quickly. Understanding multi-core technology helps explain why modern computers are so powerful compared to older single-core systems.

Input and Output Devices

Input and output devices allow users to interact with the computer. Input devices, such as keyboards, mice, and scanners, send data into the computer. Output devices, like monitors, printers, and speakers, display or present the results of processing back to the user.

Embedded Systems

An embedded system is a computer system designed to perform a specific task within a larger system. Examples include microwaves, digital watches, smart speakers or cruise control systems in cars. These systems often have limited resources and are optimised for efficiency and reliability.

Understanding embedded systems helps you see how computer architecture applies beyond traditional computers, influencing everyday technology.

Why Is System Architecture Important?

System Architecture is the foundation of computer science. It helps you understand how computers work at a fundamental level, which is essential for programming, troubleshooting, and designing new systems. Whether you’re writing code, building hardware, or simply using a computer, knowing how everything connects gives you a deeper appreciation of technology.

Metronome App (Python Challenge)

With this Python challenge, we will create a metronome app to help musicians keep the right tempo when practising their favourite tunes. By the end of this project, we will have a program that takes user input for the BPM (Beats Per Minute) and the time signature, then generates a matching tempo on screen.

Our first task is to write a Python program that:

    Takes user input for BPM (beats per minute) and time signature (e.g., 4/4, 3/4, 6/8).
    Calculates the interval between beats based on the BPM
    Generates a visual metronome on the screen, showing the beats in real-time and refreshing the screen based on the bpm and the time signature

Our second aim will be to add a menu system to our app. The menu will give the user two options:

    Option 1: The user can use the metronome from our first task and will therefore be asked to enter the BPM and time signature to use.
    Option 2: The user will be asked to enter the name of a famous rock song they would like to practise on. The program will then try to find this rock song in the rock-songs.csv file provided to find out the BPM and time signature to use to configure the metronome.

BPM and Beat Interval

The interval (in seconds) between two beats can be calculated using the given bpm of a track as follows:

So for instance with a bpm of 120 (beats per minute), the delay between two beats is: 60/120 = 0.5 seconds.

Time Signature

The time signature determines how many beats are in each measure. For example, 4/4 means 4 beats per measure, while 3/4 means 3 beats. Our metronome should group beats accordingly by clearing the screen after each measure and displaying the first beat within a measure as a “Tick” while the other beats will be displayed as “Tock”.

Python Code

Here is the full code for the first part of this challenge, enabling the user to enter the BPM and time signature to be used by the metronome.

You will need to complete this code to add the menu system and let the user configure the metronome using either option 1 (entering the BPM and time signature) or option 2 (entering a song title).

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

The Skyscraper Smart Lift Algorithm

Imagine you are the lead developer for a cutting-edge, luxurious hotel housed in a 101-floor skyscraper. The hotel’s main lift needs a smart algorithm to efficiently transport guests to their rooms. Each floor has seven rooms, and the numbering starts from the ground floor (Floor 0) with rooms 1 to 7, then Floor 1 with rooms 8 to 14, and so on, up to Floor 100 with rooms 701 to 707.

The smart lift of this hotel is equipped with a keypad that let the guests enter their room number.

Your challenge is to write a Python algorithm to control this smart lift. Your algorithm will need to:

    Take a room number as input
    Validate this room number to only accept room numbers between 1 and 707 and display an error message if the room number is invalid
    Calculate and output the corresponding floor number that the lift will have to reach.

Key Insight

You may decide to solve this problem by yourself. Alternatively you can read through the following guidance to help you solve this challenge.

Let’s first make sense of the room numbering pattern:

  • Ground Floor (Floor 0): Rooms 1, 2, 3, 4, 5, 6, 7
  • Floor 1: Rooms 8, 9, 10, 11, 12, 13, 14
  • Floor 2: Rooms 15, 16, 17, 18, 19, 20, 21
  • Floor 100: Rooms 701, 702, 703, 704, 705, 706, 707

The floor number for any given room can be calculated using integer division (//). For example:

Room 24: 24 // 7 = 3. This room will be located on the 3rd floor.

However we need to be cautious, as just applying an integer division will not work for every room:
For instance: Room 7: 7 // 7 = 1 though we know that room 7 should be on the ground floor (0).

We can therefore define a formula to help us get the correct floor number for every valid room number:

Python Code

Your turn, use the online Python IDE below to complete the code for this challenge. Then you will be able to test your code with the test plan provided below the Python IDE.

Test Plan

Use the following test plan to test your code:

Input Expected Output Pass/Fail?
Room Number: 5 Ground Floor
Room Number: 12 1
Room Number: 16 2
Room Number: 21 2
Room Number: 22 3
Room Number: 76 10
Room Number: 101 14
Room Number: 707 100
Room Number: 708 Invalid Room Number!
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Kaprekar’s Constant – Python Challenge

In this challenge, we’re going to explore a fascinating mathematical curiosity known as Kaprekar’s Constant, and then write a Python program to demonstrate how it works.

Kaprekar’s constant, number 6174 has an odd particularity: If you rearrange its four digits in descending order (7641) and take away the number made of these same 4 digits in ascending order (1467) you will fall back on the initial number 7641 – 1467 = 6174!

But that’s not all… The Indian mathematician D. R. Kaprekar discovered something amazing about 4-digit numbers. Here’s the process he found:

  1. Take any 4-digit number (at least two different digits).
    Example: 3524

  2. Rearrange its digits to create:
    • The largest possible number: 5432
    • The smallest possible number: 2345
  3. Subtract the smaller number from the larger one:
    5432 – 2345 = 3087

  4. Now take this result and repeat the process!
    Step 1: 5432 – 2345 = 3087
    Step 2: 8730 – 0378 = 8352
    Step 3: 8532 – 2358 = 6174
    Step 4: 7641 – 1467 = 6174

Once you reach 6174, the process stops — because you’ll keep getting 6174 forever!

This number, 6174, is known as Kaprekar’s Constant. No matter which 4-digit number you start with (as long as the digits aren’t all identical), you will always end up at 6174 after a few iterations!

Let’s visualise this with 2025 as our starting 4-digit number:

Python Challenge

The initial challenge is to write a Python program that:

  • Asks the user to enter a 4-digit number (with at least two different digits).
  • Applies Kaprekar’s routine (rearrange digits, subtract, repeat).
  • Displays each step of the process.
  • Stops once it reaches 6174.
  • Outputs how many iterations it took to reach the constant.

Example output:

Enter a 4-digit number: 3524

Step 1: 5432 - 2345 = 3087
Step 2: 8730 - 0378 = 8352
Step 3: 8532 - 2358 = 6174

It took 3 iterations to reach Kaprekar's constant (6174).

Python Code (Solution)

Extra Challenge

Write a program to count how many iterations it takes for every 4-digit number (from 0001 to 9998) to reach 6174. Use this program to find out both the average (mean) and the maximum number of iterations it takes to reach Kaprekar’s constant amongst all these numbers!

Warning: Make sure to remove any number with the same 4 digits (1111, 2222, 3333… as these cannot lead to Kaprekar’s constant: When applying the process described above on such a 4-digit number, the computer will loop indefinitely without reaching Kaprekar’s constant.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

The Recamán’s Sequence (Recursive Algorithm)

The Recamán’s Sequence is a well-known recursive sequence used in Mathematics and Computer Science. It can easily be implemented using a recursive function.

Recamán’s sequence a0, a1, a2, … is defined as:

The first terms of the sequence are:
0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 42, 17, 43, 16, 44, 15, 45, 14, 46, 79, 113, 78, 114, 77, 39, 78, 38, 79, 37, 80, 36, 81, 35, 82, 34, 83, 33, 84, 32, 85, 31, 86, 30, 87, 29, 88, 28, 89, 27, 90, 26, 91, 157, 224, 156, 225, 155, …

By drawing an arc between each consecutive number of the Recamán’s Sequence we can create beautiful visual representations of the sequence:

The above visualisation represents the first 70 numbers of the Recamán’s Sequence

To create this visual representation, we start with a0=0 and then draw an arc between each consecutive set of values of the sequence:

Recursive Function

Let’s implement a recursive function in Python to generate the first n values of the Recamán’s sequence:

Tagged with:

Flood-Fill Algorithm

The aim of this challenge is to demonstrate the use of a recursive algorithm used in most Graphic Editing Software when you use the fill tool to quickly and automatically fill a selected area with a solid colour.

To demonstrate this algorithm we will first initialise a 2D-array called grid that will represent our picture, each cell being a pixel of colour. We will use three integer values to represent the colours white (=0), black (=1) and purple (=2).

We will prefill our grid with mainly white pixels as well as a few random black blocks randomly positioned on the grid. We will then use a recursive algorithm, starting from a random position on the grid, to colour all adjacent white pixels using a recursive approach:

Python Code

Here is the Python code to create a visual demonstration of our recursive flood-fill algorithm:

Tagged with: